<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>JS数组演示文档</title>
    <script>
      //第一种 直接使用数组对变量进行赋值
      var A = [12, 78, 78, 78, 89];
      console.log(typeof A);
      console.log(A);

      //第二种 使用关键字 new 创建数组 先声明再赋值 (初始时未声明长度)
      var B = new Array();
      console.log(typeof B);

      B[0] = 12;
      B[1] = 34;
      B[2] = 56;
      B[4] = 58;
      console.log(B);

      //第三种  使用关键字 new 创建数组 先声明再赋值 (初始时声明长度)
      var C = new Array(3);
      console.log(C);
      console.log(typeof C);

      C[0] = 12;
      C[1] = 34;
      C[2] = 35;
      C[30] = 36;

      console.log(C);

      //第四种 使用关键字 new 创建数组 带参数构造 (参数可以是任意类型)

      var D = new Array(45, true, "hello", null, undefined, ["a", "b", "c"]);
      D[7] = new Array(1, 2, 3);
      console.log(typeof D);
      console.log(D);

      // 添加元素
      var fruits = ["Banana", "Orange", "Apple", "Mango"];
      console.log(fruits);
      fruits.push("Lemon");
      console.log(fruits);

      //删除指定元素 0
      var arr = [3, 7, 11, 0, 0, 0, 3, 0, 55];
      for (var i = arr.length - 1; i >= 0; i--) {
        if (arr[i] == 0) {
          //从哪个位置开始 删除多少数据
          arr.splice(i, 1);
        }
      }
      //   for (var index = 0; index < arr.length; index++) {
      //     if (arr[index] == 0) {
      //       arr.splice(index, 1);
      //     }
      //   }
      console.log(arr);
    </script>
  </head>
  <body></body>
</html>
